package com.example.shrio.conf;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.SessionContext;
import org.apache.shiro.session.mgt.SessionFactory;
import org.apache.shiro.web.session.mgt.DefaultWebSessionContext;

import javax.servlet.http.HttpServletRequest;

/**
 * shrio session工厂
 * 
 * @author wangkai
 *
 * @date: 2019年6月10日 上午11:14:46
 */
public class ShiroSessionFactory implements SessionFactory {

	@Override
	public Session createSession(SessionContext initData) {
		ShiroSession session = new ShiroSession();
		HttpServletRequest request = (HttpServletRequest) initData
				.get(DefaultWebSessionContext.class.getName() + ".SERVLET_REQUEST");
		String token = request.getHeader("token");
		if (token != null) {// 登陆过的(对token进行生成进行验证（token可自定义生成）以后补充)
			session.setChanged(false);
		} else {
			session.setChanged(true);
		}
		return session;
	}
}
